'use strict';
const db = uniCloud.database();
exports.main = async (event, context) => {
	//event为客户端上传的参数
	console.log('event : ', event)
	const collection = db.collection('picDetail');
	// [{"id":200,"templateId":"g45nooqk","templateUrl":"http://template.shijianhu.com/video9/f9xmfe.gif","createTime":"2023-12-14 10:35:05","deleteState":0,"typeId":9,"templateStaticUrl":"http://template.shijianhu.com/video9/f9xmfe.mp4","name":"丸子头手势舞"},{"id":201,"templateId":"324na51u","templateUrl":"http://template.shijianhu.com/video9/mm1s6j.gif","createTime":"2023-12-14 10:35:08","deleteState":0,"typeId":9,"templateStaticUrl":"http://template.shijianhu.com/video9/mm1s6j.mp4","name":"公主头手势舞"},
	for (var i = 0; i < event.length; i++) {
		let item = event[i];
		console.log('item : ', item+","+item.templateId)
		let count = await collection.where({"templateId":item.templateId}).count();
		console.log('collection.where : ', count)
		if(count.total === 0){
			let res = await collection.add(item);
			console.log('add : ', res)
		}
	}
	//返回数据给客户端
	return event
};
